package com.lzw.dao01;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import java.util.List;

public class MainActivity extends AppCompatActivity {
    public static final String TAG=MainActivity.class.getName();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "demo");
        DaoMaster master = new DaoMaster(helper.getWritableDb());
        PersonDao personDao = master.newSession().getPersonDao();
        Person person = new Person(1, "李四", 18, true);
//        personDao.insertOrReplace(person);//id相同的话就会替换
//        personDao.insertOrReplace(new Person(2, "李四", 20, false));
//        personDao.insertOrReplace(new Person(3, "李四", 15, false));
//        personDao.insertOrReplace(new Person(4, "李四", 10, false));
//        personDao.insertOrReplace(new Person(5, "李四", 30, false));
        List<Person> list = personDao.queryBuilder().where(PersonDao.Properties.Age.gt(16)).build().list();
        for (Person p : list) {
            p.setGrown(true);
        }

        personDao.updateInTx(list);
        List<Person> persons = personDao.loadAll();//查询

        for (Person p : persons) {
            Log.d(TAG,"onCreate:"+p.getName()+","+p.getAge()+","+p.getGrown());
       }


    }
}
